package com.gap.employee;

import com.buanalintas.framework.Configuration;
import com.buanalintas.framework.Controller;
import com.buanalintas.framework.Dictionary;
import com.buanalintas.framework.Field;
import com.buanalintas.framework.Formatter;
import com.buanalintas.framework.Logger;
import com.buanalintas.framework.Page;
import com.buanalintas.framework.Persistence;
import com.buanalintas.framework.Sequence;
import com.buanalintas.framework.Utility;
import com.buanalintas.framework.formatter.DateFormatter;
import com.gap.entities.GapMasterEmployee;
import com.gap.entities.GapMasterHistoryEmployee;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * Class Employee is ...
 *
 * Generated on Wed Jan 07 10:52:06 ICT 2015
 *
 * @version 1.0
 * @author Mr. Kazao™
 * @since Bynga 1.0
 *
 */
public class Employee extends Page {

    private Field employeeId;
    private Field employeeFinger;
    private Field employeeNumber;
    private Field employeeNameFirst;
//    private Field employeeNameMiddle;
//    
//    private Field employeeNameLast;
    private Field employeeTitleFirst;
    private Field employeeTitleLast;
    private Field employeeDateOfBirth;
    private Field employeePlaceOfBirth;
    private Field employeeIdNumber;
    private Field employeeAddress;
    private Field employeePostalCode;
    private Field employeePhone;
    private Field employeeMobilePhone;
    private Field employeeEmail;
    private Field employeeMarried;
    private Field employeeRegistered;
    private Field employeeSalaryBasic;
    private Field employeePaymentMethod;
    private Field employeeBankAccount;
    private Field employeeBankAccountNumber;
    private Field employeeBankAccountName;
    private Field employeeDelegation;
    private Field employeeActive;
    private Field employeePlatform;
    private Field employeeStatusBonus;
    private Field employeeDescription;
    private Field employeeUserId;
    private Field employeeSexId;
    private Field employeeStatusId;
    private Field employeeJobPositionId;
    private Field employeeEducationId;
    private Field employeeReligionId;

    public Employee() {
        super();

        setTheClass(GapMasterEmployee.class);

        employeeId = new Field();
        employeeId.setName("employeeId");
        employeeId.setCaption("id");
        //employeeId.setInfo("employee id");
        employeeId.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeId.setInputProperties(" size=\"20\"");
        getFields().add(employeeId);

        employeeFinger = new Field();
        employeeFinger.setName("employeeFinger");
        employeeFinger.setCaption("finger");
        employeeFinger.setInfo("Finger ID/PIN");
        employeeFinger.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeFinger.setInputProperties(" size=\"3\"");
        getFields().add(employeeFinger);

        employeeNumber = new Field();
        employeeNumber.setName("employeeNumber");
        employeeNumber.setCaption("number ID");
//        employeeNumber.setInfo("Automatic formated number");
        employeeNumber.setListProperties(" align=\"left\" width=\"10%\" nowrap");
        employeeNumber.setInputProperties(" size=\"18\"");
        getFields().add(employeeNumber);

        employeeNameFirst = new Field();
        employeeNameFirst.setName("employeeNameFirst");
        employeeNameFirst.setCaption("name");
        //employeeNameFirst.setInfo("employee name first");
        employeeNameFirst.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeNameFirst.setInputProperties(" size=\"30\"");
        getFields().add(employeeNameFirst);

//        employeeNameMiddle = new Field();
//        employeeNameMiddle.setName("employeeNameMiddle");
//        employeeNameMiddle.setCaption("middle name");
//        //employeeNameMiddle.setInfo("employee name middle");
//        employeeNameMiddle.setListProperties(" align=\"left\" width=\"1%\" nowrap");
//        employeeNameMiddle.setInputProperties(" size=\"16\"");        
//        getFields().add(employeeNameMiddle);
//        
//        employeeNameLast = new Field();
//        employeeNameLast.setName("employeeNameLast");
//        employeeNameLast.setCaption("last name");
//        //employeeNameLast.setInfo("employee name last");
//        employeeNameLast.setListProperties(" align=\"left\" width=\"1%\" nowrap");
//        employeeNameLast.setInputProperties(" size=\"16\"");        
//        getFields().add(employeeNameLast);
        employeeTitleFirst = new Field();
        employeeTitleFirst.setName("employeeTitleFirst");
        employeeTitleFirst.setCaption("title first");
        //employeeTitleFirst.setInfo("employee title first");
        employeeTitleFirst.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeTitleFirst.setInputProperties(" size=\"8\"");
        getFields().add(employeeTitleFirst);

        employeeTitleLast = new Field();
        employeeTitleLast.setName("employeeTitleLast");
        employeeTitleLast.setCaption("title last");
        //employeeTitleLast.setInfo("employee title last");
        employeeTitleLast.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeTitleLast.setInputProperties(" size=\"8\"");
        getFields().add(employeeTitleLast);

        employeeDateOfBirth = new Field();
        employeeDateOfBirth.setName("employeeDateOfBirth");
        employeeDateOfBirth.setCaption("date of birth");
        //employeeDateOfBirth.setInfo("employee date of birth");
        employeeDateOfBirth.setListProperties(" align=\"center\" width=\"1%\" nowrap");
        employeeDateOfBirth.setInputProperties(" size=\"8\"");
        employeeDateOfBirth.setRequired(true);
        getFields().add(employeeDateOfBirth);

        employeePlaceOfBirth = new Field();
        employeePlaceOfBirth.setName("employeePlaceOfBirth");
        employeePlaceOfBirth.setCaption("place of birth");
        //employeePlaceOfBirth.setInfo("employee place of birth");
        employeePlaceOfBirth.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeePlaceOfBirth.setInputProperties(" size=\"20\"");
        employeePlaceOfBirth.setRequired(true);
        getFields().add(employeePlaceOfBirth);

        employeeIdNumber = new Field();
        employeeIdNumber.setName("employeeIdNumber");
        employeeIdNumber.setCaption("identity number");
        employeeIdNumber.setInfo("Number of ID, driver license, pasport, other");
        employeeIdNumber.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeIdNumber.setInputProperties(" size=\"24\"");
        employeeIdNumber.setRequired(true);
        getFields().add(employeeIdNumber);

        employeeAddress = new Field();
        employeeAddress.setName("employeeAddress");
        employeeAddress.setCaption("address");
        //employeeAddress.setInfo("employee address");
        employeeAddress.setListProperties(" align=\"left\" width=\"35%\"");
        employeeAddress.setInputProperties(" cols=\"50\" rows=\"5\"");
        employeeAddress.setInputType(Field.INPUT_TEXT_AREA);
//        employeeAddress.setUseRichEditor(true);
        employeeAddress.setRequired(true);
        getFields().add(employeeAddress);

        employeePostalCode = new Field();
        employeePostalCode.setName("employeePostalCode");
        employeePostalCode.setCaption("postal code");
        //employeePostalCode.setInfo("employee postal code");
        employeePostalCode.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeePostalCode.setInputProperties(" size=\"5\"");
        getFields().add(employeePostalCode);

        employeePhone = new Field();
        employeePhone.setName("employeePhone");
        employeePhone.setCaption("phone");
        //employeePhone.setInfo("employee phone");
        employeePhone.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeePhone.setInputProperties(" size=\"14\"");
        getFields().add(employeePhone);

        employeeMobilePhone = new Field();
        employeeMobilePhone.setName("employeeMobilePhone");
        employeeMobilePhone.setCaption("mobile phone");
        //employeeMobilePhone.setInfo("employee mobile phone");
        employeeMobilePhone.setListProperties(" align=\"left\" width=\"4%\" nowrap");
        employeeMobilePhone.setInputProperties(" size=\"14\"");
        getFields().add(employeeMobilePhone);

        employeeEmail = new Field();
        employeeEmail.setName("employeeEmail");
        employeeEmail.setCaption("email");
        //employeeEmail.setInfo("employee email");
        employeeEmail.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeEmail.setInputProperties(" size=\"30\"");
        getFields().add(employeeEmail);

        employeeMarried = new Field();
        employeeMarried.setName("employeeMarried");
        employeeMarried.setCaption("married");
        //employeeMarried.setInfo("employee married");
        employeeMarried.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeMarried.setInputProperties(" ");
        employeeMarried.setInputType(Field.INPUT_CHECK_BOX);
        employeeMarried.getOptions().add(new String[]{"1", "Yes"});
        getFields().add(employeeMarried);

        employeeRegistered = new Field();
        employeeRegistered.setName("employeeRegistered");
        employeeRegistered.setCaption("registered");
        //employeeRegistered.setInfo("employee registered");
        employeeRegistered.setListProperties(" align=\"center\" width=\"1%\" nowrap");
        employeeRegistered.setInputProperties(" size=\"8\"");
        //employeeRegistered.setFormatter(DateFormatter.getInstanceDate(this));
        getFields().add(employeeRegistered);

        employeeSalaryBasic = new Field();
        employeeSalaryBasic.setName("employeeSalaryBasic");
        employeeSalaryBasic.setCaption("salary basic");
        //employeeSalaryBasic.setInfo("employee salary basic");
        employeeSalaryBasic.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeSalaryBasic.setInputProperties(" size=\"20\"");
        getFields().add(employeeSalaryBasic);

        employeePaymentMethod = new Field();
        employeePaymentMethod.setName("employeePaymentMethod");
        employeePaymentMethod.setCaption("payment method");
        //employeePaymentMethod.setInfo("employee payment method");
        employeePaymentMethod.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeePaymentMethod.setInputProperties(" size=\"20\"");
        getFields().add(employeePaymentMethod);

        employeeBankAccount = new Field();
        employeeBankAccount.setName("employeeBankAccount");
        employeeBankAccount.setCaption("bank account");
        //employeeBankAccount.setInfo("employee bank account");
        employeeBankAccount.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeBankAccount.setInputProperties(" size=\"20\"");
        getFields().add(employeeBankAccount);

        employeeBankAccountNumber = new Field();
        employeeBankAccountNumber.setName("employeeBankAccountNumber");
        employeeBankAccountNumber.setCaption("bank account number");
        //employeeBankAccountNumber.setInfo("employee bank account number");
        employeeBankAccountNumber.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeBankAccountNumber.setInputProperties(" size=\"20\"");
        getFields().add(employeeBankAccountNumber);

        employeeBankAccountName = new Field();
        employeeBankAccountName.setName("employeeBankAccountName");
        employeeBankAccountName.setCaption("bank account name");
        //employeeBankAccountName.setInfo("employee bank account name");
        employeeBankAccountName.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeBankAccountName.setInputProperties(" size=\"20\"");
        getFields().add(employeeBankAccountName);

        employeeDelegation = new Field();
        employeeDelegation.setName("employeeDelegation");
        employeeDelegation.setCaption("delegation");
        //employeeDelegation.setInfo("employee delegation");
        employeeDelegation.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeDelegation.setInputProperties(" size=\"20\"");
        getFields().add(employeeDelegation);

        employeeActive = new Field();
        employeeActive.setName("employeeActive");
        employeeActive.setCaption("active");
        //employeeActive.setInfo("employee active");
        employeeActive.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeActive.setInputProperties(" size=\"20\"");
        employeeActive.setInputType(Field.INPUT_CHECK_BOX);
        employeeActive.getOptions().add(new String[]{"1", "Yes"});
        getFields().add(employeeActive);

        employeePlatform = new Field();
        employeePlatform.setName("employeePlatform");
        employeePlatform.setCaption("platform");
        employeePlatform.setRequired(true);
        employeePlatform.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeePlatform.setInputProperties(" size=\"20\"");
        getFields().add(employeePlatform);

        employeeStatusBonus = new Field();
        employeeStatusBonus.setName("employeeStatusBonus");
        employeeStatusBonus.setCaption("status bonus");
        //employeeStatusBonus.setInfo("employee status bonus");
        employeeStatusBonus.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeStatusBonus.setInputProperties(" size=\"20\"");
        employeeStatusBonus.setInputType(Field.INPUT_RADIO_BOX);
        employeeStatusBonus.getOptions().add(new String[]{"1", "Periodik"});
        employeeStatusBonus.getOptions().add(new String[]{"2", "Gross"});
        getFields().add(employeeStatusBonus);

        employeeDescription = new Field();
        employeeDescription.setName("employeeDescription");
        employeeDescription.setCaption("description");
        //employeeDescription.setInfo("employee description");
        employeeDescription.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeDescription.setInputProperties(" size=\"20\"");
        getFields().add(employeeDescription);

        employeeUserId = new Field();
        employeeUserId.setName("employeeUserId");
        employeeUserId.setCaption("user");
        //employeeUserId.setInfo("employee user id");
        employeeUserId.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeUserId.setInputProperties(" ");
        employeeUserId.setInputType(Field.INPUT_COMBO_BOX);
        employeeUserId.setRequired(true);
        getFields().add(employeeUserId);

        employeeSexId = new Field();
        employeeSexId.setName("employeeSexId");
        employeeSexId.setCaption("sex");
        //employeeSexId.setInfo("employee sex id");
        employeeSexId.setListProperties(" align=\"left\" width=\"5%\" nowrap");
        employeeSexId.setInputProperties(" ");
        employeeSexId.setInputType(Field.INPUT_COMBO_BOX);
        employeeSexId.setRequired(true);
        getFields().add(employeeSexId);

        employeeStatusId = new Field();
        employeeStatusId.setName("employeeStatusId");
        employeeStatusId.setCaption("status");
        //employeeStatusId.setInfo("employee status id");
        employeeStatusId.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeStatusId.setInputProperties(" ");
        employeeStatusId.setInputType(Field.INPUT_COMBO_BOX);
        employeeStatusId.setRequired(true);
        getFields().add(employeeStatusId);

        employeeJobPositionId = new Field();
        employeeJobPositionId.setName("employeeJobPositionId");
        employeeJobPositionId.setCaption("job position");
        //employeeJobPositionId.setInfo("employee job position id");
        employeeJobPositionId.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeJobPositionId.setInputProperties(" ");
        employeeJobPositionId.setInputType(Field.INPUT_COMBO_BOX);
        employeeJobPositionId.setRequired(true);
        getFields().add(employeeJobPositionId);

        employeeEducationId = new Field();
        employeeEducationId.setName("employeeEducationId");
        employeeEducationId.setCaption("education");
        //employeeEducationId.setInfo("employee education id");
        employeeEducationId.getSelectorAction().add(new String[]{"value", "employeeTitleFirst", "employeeEducationTitleFirst"});
        employeeEducationId.getSelectorAction().add(new String[]{"value", "employeeTitleLast", "employeeEducationTitleLast"});
        employeeEducationId.setListProperties(" align=\"left\" width=\"1%\" nowrap");
        employeeEducationId.setInputProperties(" ");
        employeeEducationId.setInputType(Field.INPUT_COMBO_BOX);
        employeeEducationId.setRequired(true);
        getFields().add(employeeEducationId);

        employeeReligionId = new Field();
        employeeReligionId.setName("employeeReligionId");
        employeeReligionId.setCaption("religion");
        //employeeReligionId.setInfo("employee religion id");
        employeeReligionId.setInputProperties(" ");
        employeeReligionId.setInputType(Field.INPUT_COMBO_BOX);
        employeeReligionId.setRequired(true);
        getFields().add(employeeReligionId);

        fillFields();

        getFieldsUnique().add(new Field[]{employeeNumber});
        getFieldsUnique().add(new Field[]{employeeUserId});

        getGroupsAdd().add(new Group("Personal information",
                employeeNumber,
                employeeIdNumber,
                employeeNameFirst,
                //                employeeNameMiddle,
                //                employeeNameLast,
                employeePlaceOfBirth,
                employeeDateOfBirth,
                employeeSexId,
                employeeMarried,
                employeeReligionId,
                employeeEducationId,
                employeeTitleFirst,
                employeeTitleLast,
                employeeUserId,
                employeeFinger,
                //                employeeTopEmployeeId,
                employeeDelegation));
        getGroupsAdd().add(new Group("Address",
                employeeAddress,
                employeePostalCode,
                employeePhone,
                employeeMobilePhone,
                employeeEmail));
        getGroupsAdd().add(new Group("Work Information",
                employeeSalaryBasic,
                //                employeeJobGroupId,
                employeeJobPositionId,
                //                employeeWorkingTimeId,
                employeeStatusId,
                employeeStatusBonus,
                employeePlatform,
                employeeActive));

        getGroupsEdit().add(new Group("Personal information",
                employeeNumber,
                employeeIdNumber,
                employeeNameFirst,
                //                employeeNameMiddle,
                //                employeeNameLast,
                employeePlaceOfBirth,
                employeeDateOfBirth,
                employeeSexId,
                employeeMarried,
                employeeReligionId,
                employeeEducationId,
                employeeTitleFirst,
                employeeTitleLast,
                employeeUserId,
                employeeFinger,
                //                employeeTopEmployeeId,
                employeeDelegation));
        getGroupsEdit().add(new Group("Address",
                employeeAddress,
                employeePostalCode,
                employeePhone,
                employeeMobilePhone,
                employeeEmail));
        getGroupsEdit().add(new Group("Work Information",
                employeeSalaryBasic,
                //                employeeJobGroupId,
                employeeJobPositionId,
                //                employeeWorkingTimeId,
                employeeStatusId,
                employeeStatusBonus,
                employeePlatform,
                employeeActive));

        getGroupsView().add(new Group("Personal information",
                employeeNumber,
                employeeIdNumber,
                employeeNameFirst,
                //                employeeNameMiddle,
                //                employeeNameLast,
                employeePlaceOfBirth,
                employeeDateOfBirth,
                employeeSexId,
                employeeMarried,
                employeeReligionId,
                employeeEducationId,
                employeeTitleFirst,
                employeeTitleLast,
                employeeUserId,
                employeeFinger,
                employeeDelegation));
        getGroupsView().add(new Group("Address",
                employeeAddress,
                employeePostalCode,
                employeePhone,
                employeeMobilePhone,
                employeeEmail));
        getGroupsView().add(new Group("Work Information",
                employeeSalaryBasic,
                employeeJobPositionId,
                employeeStatusId,
                employeeStatusBonus,
                employeePlatform,
                employeeActive));

        getGroupsPrint().add(new Group("Personal information",
                employeeNumber,
                employeeIdNumber,
                employeeNameFirst,
                employeePlaceOfBirth,
                employeeDateOfBirth,
                employeeSexId,
                employeeMarried,
                employeeReligionId,
                employeeEducationId,
                employeeTitleFirst,
                employeeTitleLast,
                employeeUserId,
                employeeFinger,
                employeeDelegation));
        getGroupsPrint().add(new Group("Address",
                employeeAddress,
                employeePostalCode,
                employeePhone,
                employeeMobilePhone,
                employeeEmail));
        getGroupsPrint().add(new Group("Work Information",
                employeeSalaryBasic,
                employeeJobPositionId,
                employeeStatusId,
                employeeStatusBonus,
                employeePlatform,
                employeeActive));

        getFieldsList().clear();
        getFieldsList().add(employeeNumber);
        getFieldsList().add(employeeNameFirst);
        getFieldsList().add(employeeSexId);
        getFieldsList().add(employeeAddress);
        getFieldsList().add(employeeStatusBonus);
        getFieldsList().add(employeePlatform);

        getController().setOrder("t. employeeNumber");
        setExportList(getClass().getResourceAsStream("EmployeeList.jasper"));
        setExport(getClass().getResourceAsStream("Employee.jasper"));

    }

    @Override
    public void afterInit(HttpServletRequest req, HttpServletResponse res) {
        employeeDateOfBirth.setFormatter(DateFormatter.getInstanceDate(this));
        employeeRegistered.setFormatter(DateFormatter.getInstanceDate(this));
    }

    @Override
    public void beforeAdd() {
        employeeNumber.setDefaultValue(generate());
    }

    class BirthField extends Field {

        @Override
        public void prepare() {
            Formatter f = DateFormatter.getInstanceDate(null);
            setValue(employeePlaceOfBirth.getValue() + ", " + f.format(employeeDateOfBirth.getValue()));
        }
    }

    @Override
    public void beforeList() {

        Field employeeBirth = new BirthField();
        employeeBirth.setName("birth");
        employeeBirth.setCaption("Birth");
        employeeBirth.setListProperties(" width=\"10%\" nowrap");
        getFieldsList().add(2, employeeBirth);
    }

    class EmployeeController extends Controller {

        public EmployeeController(Page page) {
            super(page);
        }

        @Override
        public void beforeInsert(Object data) {
            GapMasterEmployee emp = (GapMasterEmployee) data;
//            if ("".equals(emp.getEmployeeNumber())) {
                emp.setEmployeeNumber(generate());
                System.out.println("ID Employee :"+emp.getEmployeeNumber());
//            }
        }
    }
    
     public String generate() {
        String unitCode = getCurrentUnit().getUnitCode();
        Calendar cal = Calendar.getInstance();
        String year = "" + cal.get(Calendar.YEAR);
        String month = Utility.intToRoman(cal.get(Calendar.MONTH) + 1);
        try {
            GapMasterEmployee employee = (GapMasterEmployee) getEntityManager().createQuery("SELECT t FROM GapMasterEmployee t WHERE t.employeeNumber LIKE '%/" + unitCode + "/%/" + year + "' ORDER BY t.employeeName DESC").setHint(Persistence.REFRESH_HINT, true).setFirstResult(0).setMaxResults(1).getSingleResult();
            return Utility.lpad(Integer.parseInt(employee.getEmployeeNumber().substring(0, 4)) + 1, 4, "0") + "/" + unitCode + "/" + month + "/" + year;
        } catch (Exception e) {
        }
        return "0001/" + unitCode + "/" + month + "/" + year;
    }

//    public String generate() {
//        StringBuilder format = new StringBuilder(Configuration.getFormatDate());
//        String kode = getCurrentUnit().getUnitCode();
////        Utility.replaceAll(format, "/", "");
////        Utility.replaceAll(format, "-", "");
//        DateFormatter df = new DateFormatter(format.toString());
//        Calendar cal = Calendar.getInstance();
//        String year = "" + cal.get(Calendar.YEAR);
//        try {
//            GapMasterEmployee request = (GapMasterEmployee) getEntityManager().createQuery("SELECT t FROM GapMasterEmployee t WHERE t.posNumber LIKE '%/" + kode + "/" + year + "'  ORDER BY t.employeeId DESC").setHint(Persistence.REFRESH_HINT, true).setFirstResult(0).setMaxResults(1).getSingleResult();
//            return Utility.lpad(Integer.parseInt(request.getEmployeeNumber().substring(0, 4)) + 1, 4, "0") + "/" + kode + "/" + year;
//        } catch (Exception e) {
//        }
//        return "0001/" + kode + "/" + year;
//    }

    public static GapMasterHistoryEmployee getStock(EntityManager em, GapMasterEmployee employee) {
        try {
            Query query = em.createQuery("SELECT t FROM GapMasterHistoryEmployee t WHERE "
                    + "t.historyEmployeeId=:historyEmployeeId ");
            query.setParameter("historyEmployeeId", employee);
            return (GapMasterHistoryEmployee) query.getSingleResult();
        } catch (Exception e) {
            Logger.log(e);
        }
        GapMasterHistoryEmployee stock = new GapMasterHistoryEmployee();
        stock.setHistoryId(Sequence.uuid());
        stock.setHistoryEmployeeId(employee);
        stock.setHistoryValue(BigDecimal.ZERO);
        if (!em.getTransaction().isActive()) {
            em.getTransaction().begin();
            em.persist(stock);
            em.getTransaction().commit();
        } else {
            em.persist(stock);
        }
        return stock;
    }

    @Override
    public void beforeExport() {
        getExportParams().put("title", Dictionary.getValue(this, "Employee"));
    }

    @Override
    public void beforeExportMulti() {
        beforeExport();
    }
}
